package me.jiatao.javestudy.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * Created by JiaTao on 2018/9/11.
 * Email: 535318720@qq.com
 * Version: 1.0
 * Description:
 */
public class ReflectMain {
    public static void main(String[] args) throws Exception {

        Class studentClass = Class.forName("me.jiatao.javestudy.reflect.Student");

        //获取默认的构造方法
        Constructor constructor1 = studentClass.getConstructor(new Class[]{});
        Student stu1 = (Student) constructor1.newInstance();
//        System.out.println(stu1.toString());

        //获取指定参数的构造方法
        Constructor constructor2 = studentClass.getConstructor(String.class, int.class);
        Student obj = (Student) constructor2.newInstance("jia", 28);

        Method stuMethod = studentClass.getMethod("toString");
       Object toString= stuMethod.invoke(obj);
        System.out.println(toString);

        System.out.println("---------------------------");

        Method method = ReflectMain.class.getMethod("sayHi");
        int modifiers = method.getModifiers();
        String strModif = Modifier.toString(modifiers);
        System.out.println(strModif);
    }

    public static final void sayHi() {
        System.out.println("say hi");
    }
}
